﻿@using XStudio.XCRF.Web.Models.Enums
@{
    ViewBag.Title = "患者查询";
    Layout = "~/Views/Shared/Master.cshtml";
}
<h2>患者查询</h2>
@using (Html.BeginForm())
{ 
    <p><label for="IDCard">身份证号</label>
    @Html.TextBox("IDCard")
    <label for="Name">&nbsp;姓&nbsp;名&nbsp;</label>
    @Html.TextBox("Name")</p>
    <label for="Phone">&nbsp;&nbsp; 电&nbsp;&nbsp;话&nbsp;&nbsp;</label>
    @Html.TextBox("Phone")
    <label for="SocialID">社保号</label>
    @Html.TextBox("SocialID")
    <button class="t-button t-state-default" type="submit">查询</button>
} 
@(Html.Telerik().Grid<Patient>().Name("PatientListSelfWindow")
    .DataKeys(keys => keys.Add(patient => patient.ID))
    .Columns(columns =>
    {
        columns.Bound(patient => patient.IDCard).Title("身份证号");
        columns.Bound(patient => patient.SocialID).Title("社保号");
        columns.Bound(patient => patient.Name).Title("姓名");
        columns.ForeignKey(patient => patient.Gender, GenderTypeInfo.SelectListItems, "Value", "Text").Title("性别");
        columns.Bound(patient => patient.Birthday).Title("生日");
        columns.Bound(patient => patient.Phone).Title("电话");
        columns.Command(commands =>
        {
            commands.Custom("Edit").Text("编辑").Ajax(true);
            commands.Custom("Detail").Text("查看详情").Ajax(true);
            //  if (LoginSession.IsAdministrator)
            //    commands.Delete();

        })
        .Title("操作");
    })
    .ClientEvents(events =>
    {
        events.OnCommand("OnCommand");
    })
    .DataBinding(bind =>
    {
        bind.Ajax().Select<PatientController>(c => c._PatientListSelf());
    })
    .Pageable(pager => pager.PageSize(10).Style(GridPagerStyles.NextPreviousAndNumeric))
    .Filterable(filtering => filtering
                    .Filters(filters =>
                    {
                        if (!string.IsNullOrWhiteSpace(ViewBag.IDCard as string))
                            filters.Add(o => o.IDCard).Contains(ViewBag.IDCard);
                        if (!string.IsNullOrWhiteSpace(ViewBag.Name as string))
                            filters.Add(o => o.Name).Contains(ViewBag.Name);
                        if (!string.IsNullOrWhiteSpace(ViewBag.Phone as string))
                            filters.Add(o => o.Phone).Contains(ViewBag.Phone);
                        if (!string.IsNullOrWhiteSpace(ViewBag.SocialID as string))
                            filters.Add(o => o.SocialID).Contains(ViewBag.SocialID);
                    }
          ))
    .Editable(edit => edit.Mode(GridEditMode.InLine))
        .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn).OrderBy(ord => ord.Add(o => o.IDCard)))
)
<script type="text/javascript">
    function Edit(id) {
        var url = "@(Url.Action<PatientController>(c => c.PatientEdit(Guid.Empty)))";
        url = url.replace("@Guid.Empty", id);
        window.location = url;
    }
    function Detail(id) {
        var url = "@(Url.Action<PatientController>(c => c.PatientDetail(Guid.Empty)))";
        url = url.replace("@Guid.Empty", id);
        window.location = url;
    }

    function OnCommand(e) {
        switch (e.name) {
            case "Edit": Edit(e.dataItem.ID); break;
            case "Detail": Detail(e.dataItem.ID); break;
        }
    }
</script>